package com.example.hsh.homefragment.base;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;

import com.example.hsh.homefragment.adapter.BaseAdapter;

/**
 * Created by HSH on 2016/12/13.
 */

public class BaseHolder extends RecyclerView.ViewHolder{
    SparseArray<View> views;

    public BaseHolder(View itemView, @NonNull BaseAdapter.OnItemClickListener mItemListener) {
        super(itemView);
        views = new SparseArray<>();
        if (mItemListener != null) {
            mItemListener.onItemClick(itemView, getLayoutPosition());
        }
    }

    public <T extends View> T getViewById(int id) {
        View view = views.get(id);
        if (view == null) {
            view = itemView.findViewById(id);
            views.put(id, view);
        }
        return (T) view;
    }

}
